package zack.project.domain.credit.model.aggregate;

import zack.project.domain.award.model.valobj.TaskStateVO;
import zack.project.domain.credit.event.CreditAdjustSuccessMessageEvent;
import zack.project.domain.credit.model.entity.CreditAccountEntity;
import zack.project.domain.credit.model.entity.CreditOrderEntity;
import zack.project.domain.credit.model.entity.TaskEntity;
import zack.project.domain.credit.model.valobj.TradeNameVO;
import zack.project.domain.credit.model.valobj.TradeTypeVO;
import zack.project.types.event.BaseEvent;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.RandomStringUtils;

import java.math.BigDecimal;

/**
 * @author A1793
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class TradeAggregate {

    private String userId;

    private CreditAccountEntity accountEntity;

    private CreditOrderEntity orderEntity;

    private TaskEntity taskEntity;

    public static CreditAccountEntity buildCreditAccountEntity(String userId, BigDecimal amount) {
        return CreditAccountEntity.builder()
                .adjustAmount(amount)
                .userId(userId)
                .build();
    }

    public static CreditOrderEntity buildCreditOrderEntity(String userId, BigDecimal amount, TradeNameVO tradeName, TradeTypeVO tradeType, String outBusinessNo) {

        return CreditOrderEntity.builder()
                .userId(userId)
                .tradeAmount(amount)
                .tradeName(tradeName)
                .tradeType(tradeType)
                .orderId(RandomStringUtils.randomNumeric(12))
                .outBusinessNo(outBusinessNo)
                .build();
    }
    public static TaskEntity buildTaskEntity(String userId,String topic, String messageId, BaseEvent.EventMessage<CreditAdjustSuccessMessageEvent.CreditAdjustSuccessMessage> message) {

        return TaskEntity.builder()
                .topic(topic)
                .message(message)
                .messageId(messageId)
                .userId(userId)
                .state(TaskStateVO.create)
                .build();
    }
}
